/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.niedziela12.pai.ejb.hotel.mangers;

import com.niedziela12.pai.ejb.dto.HotelDTO;
import com.niedziela12.pai.ejb.entities.Hotel;
import com.niedziela12.pai.ejb.hotel.facades.HotelFacadeLocal;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

/**
 *
 * @author Kamil
 */
@Stateless
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public class HotelManager implements HotelManagerLocal {

    @EJB
    private HotelFacadeLocal hotelFacade;

    @Override
    public void addNewHotel(HotelDTO hotel) {
        hotel.setId(null);
        hotelFacade.create(hotel.toHotel());
    }

    @Override
    public void updateHotelInfo(HotelDTO hotel) {
        hotelFacade.edit(hotel.toHotel());
    }

    @Override
    public void deleteHotel(HotelDTO hotel) {
        hotelFacade.remove(hotel.toHotel());
    }

    @Override
    public List<HotelDTO> getHotels(int from, int to) {
        List<Hotel> hotels = hotelFacade.findRange(new int[]{from,to});
        List<HotelDTO> hdto = new ArrayList<HotelDTO>();
        for(Hotel h : hotels)hdto.add(new HotelDTO(h));
        return hdto;
    }

    @Override
    public List<HotelDTO> getAllHotels() {
        List<Hotel> hotels = hotelFacade.findAll();
        List<HotelDTO> hdto = new ArrayList<HotelDTO>();
        for(Hotel h : hotels)hdto.add(new HotelDTO(h));
        return hdto;
    }

    @Override
    public int getHotelsCount() {
        return hotelFacade.count();
    }

    @Override
    public HotelDTO getHotel(Long id) {
        return new HotelDTO(hotelFacade.find(id));
    }
    
    
}
